﻿using System.Xml.Linq;

namespace SharePoint.Contrib.Extensions
{
    /// <summary>
    /// Extensions for the XAttribute class
    /// </summary>
    public static class XAttributeExtensions
    {
        /// <summary>
        /// Converts the value of the XAttribute to &lt;T&gt;
        /// </summary>
        /// <typeparam name="T">type to convert to</typeparam>
        public static T OfType<T>(this XAttribute instance)
        {
            if (instance == null)
            {
                return default(T);
            }


            if (string.IsNullOrEmpty(instance.Value) == false)
            {
                T obj = default(T);

                obj = GenericDataConverter<T>.Convert(instance.Value);
                return obj;
            }

            return default(T);

        }

    }

}
